﻿using EFCore.Extension.Logger;
using ExpressionDemo.Entity;
using Microsoft.EntityFrameworkCore;

namespace ExpressionDemo
{
    public class SqlContext:DbContext
    {
        public DbSet<Blog> Blogs { get; set; }

        public DbSet<Post> Posts { get; set; }
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);
            optionsBuilder.UseSqlServer("server=localhost;database=db729;integrated security=true;Encrypt=false");
            optionsBuilder.UseEFCoreLogger();
            //optionsBuilder.LogTo(PringSqlLog);
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            modelBuilder.ApplyConfigurationsFromAssembly(this.GetType().Assembly);
        }

       private void PringSqlLog(string msg)
        {
            Console.WriteLine(msg);
        }
    }
}
